﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Data.Model;
using NHibernate;
using DotNet.Common.NHibernateUtil;
using NHibernate.Criterion;
using ZLCMS.Business.Util;
using Newtonsoft.Json;
using ZLCMS.Web.Wap.Code;
using NHibernate.Transform;
using System.Text;
using ZLCMS.Commands.Data;

namespace ZLCMS.Web.Wap.Shop
{
    public partial class ProductDetail : MemberNoLoginPageBase
    {
        public int ProductTotalCount { get; set; }

        //public string PromotionStatus { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {

            //string api = RedisCache.GetStringValue("SYS_CFG#PROMOTION_SERVICE_IP", "") + "/api/Promotion/FindRunningStatusByProduct";
            //PromotionStatus = ZlanApiCaller.Call(api, new { ProductNoList = new string[]{Request["no"]} });

            if (string.IsNullOrEmpty(CurrentMemberAccount))
            {
                //获取cookie的数据
                string selectProducts = "";
                if (HttpContext.Current.Request.Cookies["visit_select_product"] != null)
                {
                    selectProducts = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["visit_select_product"].Value, Encoding.GetEncoding("UTF-8"));
                }

                if (!string.IsNullOrEmpty(selectProducts))
                {
                    List<SelectProductParameterData> selectProductList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SelectProductParameterData>>(selectProducts);

                    ProductTotalCount = selectProductList.Sum(p => p.Counter);
                }
            }
            else
            {
                using (ISession session = SessionFactoryHelper.CreateSession())
                {
                    ProductTotalCount = Convert.ToInt32(session.CreateQuery("select sum(ProductCount) from ShopShoppingCart where OwnerMember=:acc and  (Status='1' or Status='S') and Kind=:k ")
                        .SetParameter("k", "shop")
                        .SetParameter("acc", CurrentMemberAccount).UniqueResult());
                }
            }
        }
    }
}